﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;

namespace ClientApplication
{
    [DataContract]
    [Serializable]
    public class Jump
    {
        [DataMember]
        public string typeOfJump { get; set; }
        [DataMember]
        public double difficultyLevel { get; set; }
        [DataMember]
        public List<Score> judgesScore { get; set; }
        [DataMember]
        public double totalScore { get; set; }
        [DataMember]
        public double height { get; set; }

        public Jump() { }

        public Jump(double height)
        {
            this.height = height;
        }

        public Jump(string typeOfJump, List<Score> allJudgesScores, double height, double difficulty)
        {
            this.typeOfJump = typeOfJump;
            this.height = height;
            this.difficultyLevel = difficulty;
            this.judgesScore = allJudgesScores;
            this.totalScore = CalculateScore(allJudgesScores);
        }
        //public void AddScores
        /// <summary>
        /// Returnerar beräkning av slutgiltiga poängen enligt simhoppsalgoritmen där högsta och lägsta poängen dras av och medelvärde på resterande 
        /// multipliceras med 3*svårighetsgraden
        /// </summary>
        public double CalculateScore(List<Score> allJudgesScores)
        {
            double sum = 0;
            double max;
            double min;
            min = max = allJudgesScores[0].score;
            for (int i = 0; i < allJudgesScores.Count; i++)
            {
                if(allJudgesScores[i].score > max)
                    max = allJudgesScores[i].score;
                else if(allJudgesScores[i].score < min)
                    min = allJudgesScores[i].score;
                sum += allJudgesScores[i].score;
            }
            sum += -(min + max);
            return ((sum / (allJudgesScores.Count - 2)) * 3 * difficultyLevel);
        }
        /// <summary>
        /// För denna funktion behöver jag ha reda på:
        /// *Bestämd höjd.
        /// *Hoppkod.
        /// Stil(Position)
        /// </summary>
        


    }
}
